package info.macnana.online.oauth.resource;

import info.macnana.online.core.base.ResponseResult;
import info.macnana.online.oauth.model.AccessToken;
import info.macnana.online.oauth.service.AuthService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * author: zhengheng
 * github: https://github.com/macnana777
 * email: 517862340@qq.com
 * <p>
 * Date: 2017-08-03 9:42
 * Description: 授权验证入口
 * Copyright(©) 2017 by zhengheng.
 */
@RestController
@RequestMapping(value = "/oauth", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class JsonWebToken {

    private static final Logger LOGGER = LoggerFactory.getLogger(JsonWebToken.class);

    @Autowired
    private AuthService authService;
    /**
     * 登录校验
     * @return 登录用户的JWT
     * @throws Exception
     */
    @RequestMapping(value = "/token", method = {RequestMethod.POST, RequestMethod.GET})
    public ResponseResult<AccessToken> token() throws Exception {
//        if(loginPara == null){
//            return ResponseResult.error(Code.INVALID_USER_PASSWORD);
//        }
        //后续加入通用验证模块
        AccessToken accessToken = authService.login("macnana" , "macnana");
        return ResponseResult.success(accessToken);
    }

}
